<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class ModifyPwd extends CI_Controller {

	function __construct(){
		log_message(ETS_INFO, '### C:/admin/ModifyPwd->construct');
		parent::__construct();
		$this->load->library('mylang');
		$this->mylang->load('admin');
		$this->load->library ('mysession');
		$this->load->model('data_model');
	}
	
	public function index()
	{
		log_message(ETS_INFO, '### C:/admin/ModifyPwd->index()');
		log_message(ETS_INFO, '### goto V:/modifypwd.php');
		$this->load->view('admin/modifypwd');
	}
	public function save(){
		
		$post = $this->input->post(NULL,TRUE);
		
		$user = $this->data_model->getSingle(array('id'=>$this->mysession->getUserID()),'tb_user');
		
		if($user['password']!=md5pass($post['oldpassword'],$this->mysession->getUserName())){
			file_put_contents("test.txt", "1111111");
			show_jsonmsg(array('status'=>207,'remsg'=>lang('user_oldpasserror')));
		}
		if(trim($post['password'])!=trim($post['password1'])){
			
			show_jsonmsg(array('status'=>207,'remsg'=>lang('user_confirmerror')));
		}
		$data = array(
				'password'=>md5pass(trim($post['password']),$this->mysession->getUserName()),
				'updatetime'=>time(),
				'lastip'=>$this->input->ip_address()
		);
		file_put_contents("test.txt", $data);
		$this->data_model->editData(array('id'=>$this->mysession->getUserID()),$data,'tb_user');
		show_jsonmsg(array('status'=>205,'remsg'=>lang('submit_sucsess')));
	}
}
